﻿
namespace AR.Web.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.Linq;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using AR.Entities;


    // Implements application logic using the AR_DBEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    [EnableClientAccess()]
    public class EntretienOraleService : LinqToEntitiesDomainService<AR_DBEntities>
    {

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'CANDIDAT' query.
        public IQueryable<CANDIDAT> GetCANDIDAT()
        {
            return this.ObjectContext.CANDIDAT;
        }

        public void InsertCANDIDAT(CANDIDAT cANDIDAT)
        {
            if ((cANDIDAT.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(cANDIDAT, EntityState.Added);
            }
            else
            {
                this.ObjectContext.CANDIDAT.AddObject(cANDIDAT);
            }
        }

        public void UpdateCANDIDAT(CANDIDAT currentCANDIDAT)
        {
            this.ObjectContext.CANDIDAT.AttachAsModified(currentCANDIDAT, this.ChangeSet.GetOriginal(currentCANDIDAT));
        }

        public void DeleteCANDIDAT(CANDIDAT cANDIDAT)
        {
            if ((cANDIDAT.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(cANDIDAT, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.CANDIDAT.Attach(cANDIDAT);
                this.ObjectContext.CANDIDAT.DeleteObject(cANDIDAT);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'CRITERE' query.
        public IQueryable<CRITERE> GetCRITERE()
        {
            return this.ObjectContext.CRITERE;
        }

        public void InsertCRITERE(CRITERE cRITERE)
        {
            if ((cRITERE.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(cRITERE, EntityState.Added);
            }
            else
            {
                this.ObjectContext.CRITERE.AddObject(cRITERE);
            }
        }

        public void UpdateCRITERE(CRITERE currentCRITERE)
        {
            this.ObjectContext.CRITERE.AttachAsModified(currentCRITERE, this.ChangeSet.GetOriginal(currentCRITERE));
        }

        public void DeleteCRITERE(CRITERE cRITERE)
        {
            if ((cRITERE.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(cRITERE, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.CRITERE.Attach(cRITERE);
                this.ObjectContext.CRITERE.DeleteObject(cRITERE);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ENT_ORALE_CRITERE' query.
        public IQueryable<ENT_ORALE_CRITERE> GetENT_ORALE_CRITERE()
        {
            return this.ObjectContext.ENT_ORALE_CRITERE;
        }

        public void InsertENT_ORALE_CRITERE(ENT_ORALE_CRITERE eNT_ORALE_CRITERE)
        {
            if ((eNT_ORALE_CRITERE.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(eNT_ORALE_CRITERE, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ENT_ORALE_CRITERE.AddObject(eNT_ORALE_CRITERE);
            }
        }

        public void UpdateENT_ORALE_CRITERE(ENT_ORALE_CRITERE currentENT_ORALE_CRITERE)
        {
            this.ObjectContext.ENT_ORALE_CRITERE.AttachAsModified(currentENT_ORALE_CRITERE, this.ChangeSet.GetOriginal(currentENT_ORALE_CRITERE));
        }

        public void DeleteENT_ORALE_CRITERE(ENT_ORALE_CRITERE eNT_ORALE_CRITERE)
        {
            if ((eNT_ORALE_CRITERE.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(eNT_ORALE_CRITERE, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.ENT_ORALE_CRITERE.Attach(eNT_ORALE_CRITERE);
                this.ObjectContext.ENT_ORALE_CRITERE.DeleteObject(eNT_ORALE_CRITERE);
            }
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        // To support paging you will need to add ordering to the 'ENTERTIEN_ORALE' query.
        public IQueryable<ENTRETIEN_ORALE> GetENTERTIEN_ORALE()
        {
            return this.ObjectContext.ENTRETIEN_ORALE;
        }

        public void InsertENTERTIEN_ORALE(ENTRETIEN_ORALE eNTERTIEN_ORALE)
        {
            if ((eNTERTIEN_ORALE.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(eNTERTIEN_ORALE, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ENTRETIEN_ORALE.AddObject(eNTERTIEN_ORALE);
            }
        }

        public void UpdateENTERTIEN_ORALE(ENTRETIEN_ORALE currentENTERTIEN_ORALE)
        {
            this.ObjectContext.ENTRETIEN_ORALE.AttachAsModified(currentENTERTIEN_ORALE, this.ChangeSet.GetOriginal(currentENTERTIEN_ORALE));
        }

        public void DeleteENTERTIEN_ORALE(ENTRETIEN_ORALE eNTERTIEN_ORALE)
        {
            if ((eNTERTIEN_ORALE.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(eNTERTIEN_ORALE, EntityState.Deleted);
            }
            else
            {
                this.ObjectContext.ENTRETIEN_ORALE.Attach(eNTERTIEN_ORALE);
                this.ObjectContext.ENTRETIEN_ORALE.DeleteObject(eNTERTIEN_ORALE);
            }
        }
        public ENTRETIEN_ORALE GetEntretienByCandidatID(int id)
        {
            return this.ObjectContext.ENTRETIEN_ORALE.Where(_ => _.ID_CANDIDAT == id).FirstOrDefault();
        }


        public IQueryable<ENT_ORALE_CRITERE> FindEntretienOralCriteresByEntretienOralId(int id)
        {
            return this.ObjectContext.ENT_ORALE_CRITERE.Where(_ => _.ID_ENT_OR == id);


        }
    }
}


